from l0n0lc import jit, 映射函数, toCString  # 这里替换成你实际的 jit 引入路径

@映射函数(print, ['<iostream>'])
def cpp_cout(*args):
    code = f'std::cout'
    for arg in args:
        code += f'<< {toCString(arg)} << " "'
    code += '<< std::endl;'
    return code

# 假设通用信息.工作文件夹地址 已经配置好
@jit(每次运行都重新编译=True)
def sum_and_filter(n: int) -> int:
    print('n = ', n)
    total: int = 0
    for x in range(n):
        if x % 2 == 0:  # 测试 if 分支 + 二元运算
            total = total + x
        else:
            total = total - x
    print('total = ', total)
    return total

def test_jit_sum_and_filter():
    # 1. 基础功能测试
    assert sum_and_filter(5) == (0 + 2 + 4) - (1 + 3)

    # 2. 边界值测试
    assert sum_and_filter(0) == 0
    assert sum_and_filter(1) == 0  # 只有 0

    # 3. 大输入测试（性能 & JIT 缓存验证）
    big_result = sum_and_filter(1000)
    assert isinstance(big_result, int)

    print("所有 JIT 测试通过 ✅")

if __name__ == "__main__":
    test_jit_sum_and_filter()
